﻿using SolidworksDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestExe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SolidworksDLL.SolidWorksHelp.Test();


        }

        private void button2_Click(object sender, EventArgs e)
        {           
            bool b = SolidworksDLL.SolidWorksHelp.GetSwAPP();
            if (b)
            {
                MessageBox.Show("获取成功");

            }
            else
            {
                MessageBox.Show("获取失败");
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool b = SolidworksDLL.SolidWorksHelp.OpenSwApp();           
            if (b)
            {
                MessageBox.Show("获取成功");

            }
            else
            {
                MessageBox.Show("获取失败");
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {            
            bool b = SolidworksDLL.SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取失败");
                return;
            }

            MessageBox.Show("路径：" + SolidworksDLL.TestSW.GetPath() + ",版本：" + SolidworksDLL.TestSW.GetVer());

            SolidworksDLL.TestSW.MakeWindowsSate(1);
            Thread.Sleep(2 * 1000);
            SolidworksDLL.TestSW.MakeWindowsSate(2);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }        
            string temPath = @"D:\工作\Solidworks文件\设计模板\文件模板\锋馥零件模板.prtdot";
            string result = ModelDocHelp.NewDocumnet(temPath);
            if (result == "")
            {
                MessageBox.Show("创建零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string partPath = @"C:\Users\lzhao\Desktop\测试\02.011.A0165.123456.0007.sldprt";
            string result = ModelDocHelp.SaveDoc(partPath);
            if (result == "")
            {
                MessageBox.Show("保存零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }

        }

        private void button7_Click(object sender, EventArgs e)
        {
            //bool b = SolidWorksHelp.GetSwAPP();
            //if (false == b)
            //{
            //    MessageBox.Show("获取SolidWorks失败");
            //    return;
            //}
            //string partPath = @"C:\Users\lzhao\Desktop\测试\0001\02.011.A0165.123456.0004.sldprt";
            //string result = ModelDocHelp.OpenDoc(partPath,ref);
            //if (result == "")
            //{
            //    MessageBox.Show("打开零件成功");
            //}
            //else
            //{
            //    MessageBox.Show(result);
            //}

        }

        private void button8_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            List<string> paths = ModelDocHelp.GetAllDoc();
            foreach (var item in paths)
            {
                textBox1.AppendText(Environment.NewLine + item);
            }

        }

        private void button9_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string str = ModelDocHelp.GetActiveDoc();
            textBox1.AppendText(Environment.NewLine + str);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string str = ModelDocHelp.GetEditTarget();
            textBox1.AppendText(Environment.NewLine + str);

        }

        private void button11_Click(object sender, EventArgs e)
        {
            //openFileDialog1.InitialDirectory = "C:\\";
            //openFileDialog1.Filter = "(*.SLDASM)|";
            //openFileDialog1.ShowDialog();
            //string partPath = openFileDialog1.FileName;            
            //if (Path.GetExtension(partPath) != ".SLDASM")
            //{
            //    MessageBox.Show("请选择SolidWorks装配体文件");
            //    return;
            //}                     
            //bool b = SolidWorksHelp.GetSwAPP();
            //if (false == b)
            //{
            //    SolidWorksHelp.OpenSwApp();
            //}           
            //ModelDocHelp.OpenDoc(partPath);
            //List<string> paths = ModelDocHelp.GetAllDoc();
            //foreach (var item in paths)
            //{
            //    textBox1.AppendText(Environment.NewLine + item);               
            //}
            //MessageBox.Show("零件加载成功！");
        }
    }
}
